#!/bin/bash
export CHARLES_HOME=$HOME/.local/share/CharlesScripts/charles
export CHARLES_BACKUP=$HOME/.config/CharlesBackup

if [[ $(uname) == 'Darwin' ]]; then
    OS='Darwin'
else
    OS=$(cat /etc/issue | cut -f 1 -d ' ')
fi
case $OS in
'Arch') INSTALL() { sudo pacman -S $@; } ;;
'Ubuntu') INSTALL() { sudo apt install $@ -y --allow-unauthenticated; } ;;
'Darwin') INSTALL() { brew install $@; } ;;
*) echo 'Your distribution has not implementd yet, please modify this command' ;;
esac
CONF_DIR=$HOME/.config/fish/conf.d
if [[ ! -d $CONF_DIR ]]; then
    mkdir -p $CONF_DIR
fi
mkdir -p ~/.cabal/bin

if [ $(which autojump | wc -l) == 0 ]; then INSTALL autojump; fi
if [ -f /usr/share/autojump/autojump.fish ];then ln -sf /usr/share/autojump/autojump.fish $CONF_DIR/autojump.fish;fi
if [ -f /usr/local/share/autojump/autojump.fish ];then ln -sf /usr/local/share/autojump/autojump.fish $CONF_DIR/autojump.fish;fi

ln -sf $CHARLES_HOME/shell.rc.d/init.fish $CONF_DIR/charles.fish



#ABBRS
fish -c "abbr -a -U -- axel 'axel -acn50'"
fish -c "abbr -a -U -- ccat 'ccat --bg=dark'"
fish -c "abbr -a -U -- c 'clear; cd'"
fish -c "abbr -a -U -- ... 'cd ../..'"
fish -c "abbr -a -U -- cl 'cd ..;ls'"
fish -c "abbr -a -U -- cling 'cling --std=c++17'"
fish -c "abbr -a -U -- dd 'dd status=progress'"
fish -c "abbr -a -U -- du. 'du . --max-depth 1 -h'"
fish -c "abbr -a -U -- eg 'grep -E'"
fish -c "abbr -a -U -- emacsc 'emacs --no-window-system'"
fish -c "abbr -a -U -- fd 'fd -IL'"
fish -c "abbr -a -U -- fpv fzf\ --preview\ \'ccat\ --color=always\ \{\}\'"
fish -c "abbr -a -U -- ftps 'python3 -m http.server 8080'"
fish -c "abbr -a -U -- gaa 'git add -A'"
fish -c "abbr -a -U -- gb 'git branch'"
fish -c "abbr -a -U -- gck 'git checkout'"
fish -c "abbr -a -U -- gcm 'git commit -m'"
fish -c "abbr -a -U -- gitup 'for i in (ls);cd $i;git checkout .;git pull&;cd ..;end'"
fish -c "abbr -a -U -- gl 'git l'"
fish -c "abbr -a -U -- gm 'git merge --no-ff'"
fish -c "abbr -a -U -- gp 'git push'"
fish -c "abbr -a -U -- gpl 'git pull'"
fish -c "abbr -a -U -- gst 'git status'"
fish -c "abbr -a -U -- histg 'history | grep'"
fish -c "abbr -a -U -- i ipython"
fish -c "abbr -a -U -- lal 'ls -lahF'"
fish -c "abbr -a -U -- la 'ls -a'"
fish -c "abbr -a -U -- le 'ls|egrep'"
fish -c "abbr -a -U -- lf 'ls -lah --full-time'"
fish -c "abbr -a -U -- lg 'ls -a|grep -i'"
fish -c "abbr -a -U -- ll 'ls -lhF'"
fish -c "abbr -a -U -- l ls"
fish -c "abbr -a -U -- mag2torrent 'aria2c --bt-metadata-only=true --bt-save-metadata=true'"
fish -c "abbr -a -U -- n 'open .'"
fish -c "abbr -a -U -- o open"
fish -c "abbr -a -U -- pcs 'proxychains -q'"
fish -c "abbr -a -U -- pdb 'python -mpowerline.bindings.pdb'"
fish -c "abbr -a -U -- pp pypy3"
fish -c "abbr -a -U -- p python"
fish -c "abbr -a -U -- r ranger"
fish -c "abbr -a -U -- socksp 'export ALL_PROXY=socks5://127.0.0.1:1080'"
fish -c "abbr -a -U -- sshp ssh\ -o\ ProxyCommand=\'nc\ -x\ 127.0.0.1:1080\ \%h\ \%p\'"
fish -c "abbr -a -U -- su 'sudo su'"
fish -c "abbr -a -U -- wget 'wget -c -nc -t0'"

case $OS in
'Ubuntu') fish -c "abbr u 'apt-upgrade'" ;;
'Arch') fish -c "abbr u 'pacman -Syu;pacman -Rs (pacman -Qtdq)'" ;;
esac
